package com.ygl.strategy.sentinel.configuration;

import com.ygl.strategy.sentinel.constant.SentinelStrategyConstant;
import com.ygl.strategy.sentinel.loader.SentinelRuleLoader;
import com.ygl.strategy.sentinel.parser.*;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.annotation.PostConstruct;

/**
 * @Author yanggld
 * @Date 2020/1/10-10:52
 * @Description
 */
@Slf4j
@Configuration
@ConditionalOnProperty(value = SentinelStrategyConstant.SPRING_APPLICATION_STRATEGY_SENTINEL_ENABLED, matchIfMissing = false)
public class SentinelStrategyAutoConfiguration {
	@Autowired
	private SentinelRuleLoader sentinelRuleLoader;

	@PostConstruct
	public void initialize() {
		log.info("-------------- Load Sentinel Config --------------");

		sentinelRuleLoader.load();

		log.info("--------------------------------------------------");
	}

	@Bean
	public SentinelFlowRuleParser sentinelFlowRuleParser() {
		return new SentinelFlowRuleParser();
	}

	@Bean
	public SentinelDegradeRuleParser sentinelDegradeRuleParser() {
		return new SentinelDegradeRuleParser();
	}

	@Bean
	public SentinelAuthorityRuleParser sentinelAuthorityRuleParser() {
		return new SentinelAuthorityRuleParser();
	}

	@Bean
	public SentinelSystemRuleParser sentinelSystemRuleParser() {
		return new SentinelSystemRuleParser();
	}

	@Bean
	public SentinelParamFlowRuleParser sentinelParamFlowRuleParser() {
		return new SentinelParamFlowRuleParser();
	}

}
